import { createSlice } from '@reduxjs/toolkit'

export const counterSlice = createSlice({
    name: 'counter',
    initialState: {
        value: 0
    },
    reducers: {
        increment: (state) => {
            state.value +=1
        },
        decrement: (state) => {
            state.value -=1
        },
        incrementByAmount: (state) => {
            state.value += state.payload
        }
    }
})
// 每个 case reducer函数会生成对应的Action creators
// 为什么会这样写呢？
export const { increment,decrement,incrementByAmount } = counterSlice.actions
// counterSlice.actions 为什么包含increment、decrement、incrementByAmount这些函数
console.log('counterSlice.actions',counterSlice.actions)
// counterSlice.reducer 又是什么呢？
console.log('counterSlice.reducer',counterSlice.reducer)
export default counterSlice.reducer